﻿/* 
 * Copyright (c) 2010 Letwory Interactive
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * -- Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * -- Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * Original contributor: Nathan Letwory
 */

using System;

namespace VerseSharp
{
    public delegate void TagGroupSubscribeCallback(TagGroupSubscribeCommand command);
    public delegate void TagGroupUnsubscribeCallback(TagGroupSubscribeCommand command);

    public class TagGroupSubscribeCommand: IVerseCommand
    {
        /// <summary>
        /// Command ID
        /// </summary>
        public CommandID ID { get { return CommandID.TagGroupSubscribe; } }
        /// <summary>
        /// ID of the node being accessed.
        /// </summary>
        public uint NodeID;
        /// <summary>
        /// ID of the group being accessed. To create a new group, set it to ushort.MaxValue.
        /// Setting it to the ID of an existing group results in renaming the specified group.
        /// </summary>
        public ushort GroupID;
        /// <summary>
        /// True when subscribed, otherwise false.
        /// </summary>
        public bool Subscribed;

        public void Deserialize(byte[] source, ref int pos)
        {
            NodeID = Utils.GetUInt32(source, ref pos);
            GroupID = Utils.GetUInt16(source, ref pos);
            Subscribed = Utils.GetUInt8(source, ref pos) != 0;
        }

        public void Serialize(byte[] destination, ref int pos)
        {
            Utils.PutUInt32(destination, ref pos, NodeID);
            Utils.PutUInt16(destination, ref pos, GroupID);
            Utils.PutUInt8(destination, ref pos, (byte)(Subscribed == true ? 1 : 0));
        }
    }
}
